home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / dosref21.zip / CHAPTER.007 < prev    next >
Text File  |  1991-09-05  |  36KB  |  620 lines

  1.  
  2.        **  Programmer's Technical Reference for MSDOS and the IBM PC **
  3.                 USA copyright TXG 392-616  ALL RIGHTS RESERVED
  4. ───────────────────────────────┤ DOSREF (tm) ├────────────────────────────────
  5.                      ISBN 1-878830-02-3 (disk-based text)
  6.                     Copyright (c) 1987, 1991 Dave Williams
  7.                         ┌─────────────────────────────┐
  8.                         │ Shareware Version, 09/05/91 │
  9.                         │  Please Register Your Copy  │
  10.                         └─────────────────────────────┘
  11.  
  12.  
  13.                            C H A P T E R   S E V E N
  14.  
  15.                               DOS FILE STRUCTURE
  16.  
  17.  
  18.  
  19. FILE MANAGEMENT FUNCTIONS├─────────────────────────────────────────────────────
  20.  
  21.  Use DOS function calls to create, open, close, read, write, rename, find, and 
  22. erase files. There are two sets of function calls that DOS provides for support
  23. of file management. They are:
  24.  
  25.    * File Control Block function calls   (0Fh-24h)
  26.    * Handle function calls               (39h-69h)
  27.  
  28.  Handle function calls are easier to use and are more powerful than FCB calls.
  29. Microsoft recommends that the handle function calls be used when writing new
  30. programs. DOS 3.0 up have been curtailing use of FCB function calls; it is
  31. possible that future versions of DOS may not support FCB function calls.
  32.  
  33.  The following table compares the use of FCB calls to Handle function calls:
  34.  
  35.    ┌──────────────────────────────┬─────────────────────────────────────────┐
  36.    │           FCB Calls          │               Handle Calls              │
  37.    ├──────────────────────────────┼─────────────────────────────────────────┤
  38.    │  Access files in current     │  Access files in ANY directory          │
  39.    │  directory only.             │                                         │
  40.    │                              │                                         │
  41.    │  Requires the application    │  Does not require use of an FCB.        │
  42.    │  program to maintain a file  │  Requires a string with the drive,      │
  43.    │  control block to open,      │  path, and filename to open, create,    │
  44.    │  create, rename or delete    │  rename, or delete a file. For file     │
  45.    │  a file. For I/O requests,   │  I/O requests, the application program  │
  46.    │  the application program     │  must maintain a 16 bit file handle     │
  47.    │  also needs an FCB           │  that is supplied by DOS.               │
  48.    └──────────────────────────────┴─────────────────────────────────────────┘
  49.  
  50.  The only reason an application should use FCB function calls is to maintain
  51. the ability to run under DOS 1.x. To to this, the program may use only function
  52. calls 00h-2Eh. Though the FCB function calls are frowned upon, many of the 
  53. introductory assembly language programming texts use the FCB calls as examples.
  54.  
  55.  
  56.  
  57. FCB FUNCTION CALLS ├───────────────────────────────────────────────────────────
  58.  
  59.  FCB function calls require the use of one File Control Block per open file, 
  60. which is maintained by the application program and DOS. The application program
  61. supplies a pointer to the FCB and fills in ther appropriate fields required by 
  62. the specific function call. An FCB function call can perform file management on
  63. any valid drive, but only in the current logged directory. By using the current
  64. block, current record, and record length fields of the FCB, you can perform 
  65. sequential I/O by using the sequential read or write function calls. Random I/O
  66. can be performed by filling in the random record and record length fields. 
  67.  
  68.  Several possible uses of FCB type calls are considered programming errors and 
  69. should not be done under any circumstances to avoid problems with file sharing
  70. and compatibility with later versions of DOS.
  71.  Some errors are:
  72. 1) If program uses the same FCB structure to access more than one open file. By
  73.    opening a file using an FCB, doing I/O, and then replacing the filename field
  74.    in the file control block with a new filename, a program can open a second
  75.    file using the same FCB. This is invalid because DOS writes control info-
  76.    rmation about the file into the reserved fields of the FCB. If the program
  77.    then replaces the filename field with the original filename and then tries to
  78.    perform I/O on this file, DOS may become confused because the control info-
  79.    rmation has been changed. An FCB should never be used to open a second file
  80.    without closing the one that is currently open. If more than one File Control
  81.    Block is to be open concurrently, separate FCBs should be used.
  82.  
  83. 2) A program should never try to use the reserved fields in the FCB, as the
  84.    function of the fields changes with different versions of DOS.
  85.  
  86. 3) A delete or a rename on a file that is currently open is considered an error
  87.    and should not be attempted by an application program.
  88.  
  89.  It is also good programming practice to close all files when I/O is done. This
  90. avoids potential file sharing problems that require a limit on the number of
  91. files concurrently open using FCB function calls.
  92.  
  93.  
  94.  
  95. HANDLE FUNCTION CALLS├─────────────────────────────────────────────────────────
  96.  
  97.  The recommended method of file management is by using the extended "handle" 
  98. set of function calls. These calls are not restricted to the current directory.
  99. Also, the handle calls allow the application program to define the type of 
  100. access that other processes can have concurrently with the same file if the file
  101. is being shared.
  102.  
  103.  To create or open a file, the application supplies a pointer to an ASCIIZ 
  104. string giving the name and location of the file. The ASCIIZ string contains an 
  105. optional drive letter, optional path, mandatory file specification, and a 
  106. terminal byte of 00h. The following is an example of an ASCIIZ string:
  107.  
  108.                   format [drive][path] filename.ext,0
  109.  
  110.                       DB "A:\path\filename.ext",0
  111.  
  112.  If the file is being created, the application program also supplies the 
  113. attribute of the file. This is a set of values that defines the file read 
  114. only, hidden, system, directory, or volume label.
  115.  
  116.  If the file is being opened, the program can define the sharing and access 
  117. modes that the file is opened in. The access mode informs DOS what operations 
  118. your program will perform on this file (read-only, write-only, or read/write) 
  119. The sharing mode controls the type of operations other processes may perform 
  120. concurrently on the file. A program can also control if a child process inherits
  121. the open files of the parent. The sharing mode has meaning only if file sharing
  122. is loaded when the file is opened.
  123.  
  124.  To rename or delete a file, the appplication program simply needs to provide 
  125. a pointer to the ASCIIZ string containing the name and location of the file 
  126. and another string with the new name if the file is being renamed.
  127.  
  128.  The open or create function calls return a 16-bit value referred to as the 
  129. file handle. To do any I/O to a file, the program uses the handle to reference
  130. the file. Once a file is opened, a program no longer needs to maintain the 
  131. ASCIIZ string pointing to the file, nor is there any need to stay in the same 
  132. directory. DOS keeps track of the location of the file regardless of what 
  133. directory is current.
  134.  
  135.  Sequential I/O can be performed using the handle read (3Fh) or write (40h) 
  136. function calls. The offset in the file that IO is performed to is automatically
  137. moved to the end of what was just read or written. If random I/O is desired, the
  138. LSEEK (42h) function call can be used to set the offset into the file where I/O 
  139. is to be performed.
  140.  
  141.  
  142. SPECIAL FILE HANDLES├──────────────────────────────────────────────────────────
  143.  
  144.  DOS reserves five special file handles for use by itself and applications 
  145. programs. They are:
  146. ┌───────┬────────┬─────────────────────────────────────────────────────────────┐
  147. │ 0000h │ STDIN  │ standard input device        (input can be redirected)      │
  148. │ 0001h │ STDOUT │ standard output device       (output can be redirected)     │
  149. │ 0002h │ STDERR │ standard error output device (output cannot be redirected)  │
  150. │ 0004h │ STDAUX │ standard auxiliary device                                   │
  151. │ 0005h │ STDPRN │ standard printer device                                     │
  152. └───────┴────────┴─────────────────────────────────────────────────────────────┘
  153.  
  154.  These handles are predefined by DOS and can be used by an application program.
  155. They do not need to be opened by a program, although a program can close these 
  156. handles. STDIN should be treated as a read-only file, and STDOUT and STDERR 
  157. should be treated as write-only files. STDIN and STDOUT can be redirected. All 
  158. handles inherited by a process can be redirected, but not at the command line.
  159.  These handles are very useful for doing I/O to and from the console device. 
  160. For example, you could read input from the keyboard using the read (3Fh) 
  161. function call and file handle 0000h (STDIN), and write output to the console 
  162. screen with the write function call (40h) and file handle 0001h (STDOUT). If 
  163. you wanted an output that could not be redirected, you could output it using 
  164. file handle 0002h (STDERR). This is very useful for error messages that must 
  165. be seen by a user.
  166.  
  167.  File handles 0003h (STDAUX) and 0004h (STDPRN) can be both read from and 
  168. written to. STDAUX is typically a serial device and STDPRN is usually a parallel
  169. device.
  170.  
  171.  
  172. ASCII and BINARY MODE├─────────────────────────────────────────────────────────
  173.  
  174.  I/O to files is done in binary mode. This means that the data is read or 
  175. written without modification. However, DOS can also read or write to devices in
  176. ASCII mode. In ASCII mode, DOS does some string processing and modification to 
  177. the characters read and written. The predefined handles are in ASCII mode when 
  178. initialized by DOS. All other file handles that don't refer to devices are in 
  179. binary mode. A program, can use the IOCTL (44h) function call to set the mode 
  180. that I/O is to a device. The predefined file handles are all devices, so the 
  181. mode can be changed from ASCII to binary via IOCTL. Regular file handles that 
  182. are not devices are always in binary mode and cannot be changed to ASCII mode.
  183.  
  184.  The ASCII/BINARY bit was called "raw" in DOS 2.x, but it is called ASCII/BINARY
  185. in DOS 3.x.
  186.  
  187.  The predefined file handles STDIN (0000h) and STDOUT (0001h) and STDERR 
  188. (0002h) are all duplicate handles. If the IOCTL function call is used to change
  189. the mode of any of these three handles, the mode of all three handles is 
  190. changed. For example, if IOCTL was used to change STDOUT to binary mode, then 
  191. STDIN and STDERR would also be changed to binary mode.
  192.  
  193.  
  194.  
  195. FILE I/O IN BINARY (RAW) MODE├─────────────────────────────────────────────────
  196.  
  197. The following is true when a file is read in binary mode:
  198.  
  199. 1)  The characters ^S (scroll lock), ^P (print screen), ^C (control break) are 
  200.     not checked for during the read. Therefore, no printer echo occurs if ^S or
  201.     ^P are read.
  202. 2)  There is no echo to STDOUT (0001h).
  203. 3)  Read the number of specified bytes and returns immediately when the last 
  204.     byte is received or the end of file reached.
  205. 4)  Allows no editing of the ine input using the function keys if the input is 
  206.     from STDIN (0000h).
  207.  
  208.  
  209. The following is true when a file is written to in binary mode:
  210.  
  211. 1)  The characters ^S (scroll lock), ^P (print screen), ^C (control break) are 
  212.     not checked for during the write. Therefore, no printer echo occurs.
  213. 2)  There is no echo to STDOUT (0001h).
  214. 3)  The exact number of bytes specified are written.
  215. 4)  Does not caret (^) control characters. For example, ctrl-D is sent out as 
  216.     byte 04h instead of the two bytes ^ and D.
  217. 5)  Does not expand tabs into spaces. 
  218.  
  219.  
  220. FILE I/O IN ASCII (COOKED) MODE├───────────────────────────────────────────────
  221.  
  222. The following is true when a file is read in ASCII mode:
  223.  
  224. 1)  Checks for the characters ^C,^S, and ^P.
  225. 2)  Returns as many characters as there are in the device input buffer, or the 
  226.     number of characters requested, whichever is less. If the number of 
  227.     characters requested was less than the number of characters in the device 
  228.     buffer, then the next read will address the remaining characters in the 
  229.     buffer.
  230. 3)  If there are no more bytes remaining in the device input buffer, read a 
  231.     line (terminated by ^M) into the buffer. This line may be edited with the 
  232.     function keys. The characters returned terminated with a sequence of 0Dh,
  233.     0Ah (^M,^J) if the number of characters requested is sufficient to include
  234.     them. For example, if 5 characters were requested, and only 3 were entered
  235.     before the carriage return (0Dh or ^M) was presented to DOS from the console
  236.     device, then the 3 characters entered and 0Dh and 0Ah would be returned. 
  237.     However, if 5 characters were requested and 7 were entered before the 
  238.     carriage return, only the first 5 characters would be returned. No 0Dh,0Ah 
  239.     sequence would be returned in this case. If less than the number of 
  240.     characters requested are entered when the carriage return is received, the
  241.     characters received and 0Dh,0Ah would be returned. The reason the 0Ah 
  242.     (linefeed or ^J) is added to the returned characters is to make the devices
  243.     look like text files.
  244. 4)  If a 1Ah (^Z) is found, the input is terminated at that point. No 0Dh,0Ah 
  245.     (CR,LF) sequence is added to the string.
  246. 5)  Echoing is performed.
  247. 6)  Tabs are expanded.
  248.  
  249.  
  250. The following is true when a file is written to in ASCII mode:
  251.  
  252. 1)  The characters ^S,^P,and ^C are checked for during the write operation.
  253. 2)  Expands tabs to 8-character boundaries and fills with spaces (20h).
  254. 3)  Carets control characters, for example, ^D is written as two bytes, ^ and D.
  255. 4)  Bytes are output until the number specified is output or a ^Z is 
  256.     encountered. The number actually output is returned to the user.
  257.  
  258.  
  259. NUMBER OF OPEN FILES ALLOWED├──────────────────────────────────────────────────
  260.  
  261.  The number of files that can be open concurrently is restricted by DOS. This 
  262. number is determined by how the file is opened or created (FCB or handle 
  263. function call) and the number specified by the FCBS and FILES commands in the 
  264. CONFIG.SYS file. The number of files allowed open by FCB function calls and the
  265. number of files that can be opened by handle type calls are independent of one 
  266. another.
  267.  
  268.  
  269. RESTRICTIONS ON FCB USAGE├─────────────────────────────────────────────────────
  270.  
  271.  If file sharing is not loaded using the SHARE command, there are no 
  272. restrictions on the nuumber of files concurrently open using FCB function calls.
  273.  
  274.  However, when file sharing is loaded, the maximum number of FCBs open is set
  275. by the the FCBS command in the CONFIG.SYS file.
  276.  
  277.  The FCBS command has two values you can specify, 'm' and 'n'. The value for 
  278. 'm' specifies the number of files that can be opened by FCBs, and the value 'n' 
  279. specifies the number of FCBs that are protected from being closed.
  280.  
  281.  When the maximum number of FCB opens is exceeded, DOS automatically closes the
  282. least recently used file. Any attempt to access this file results in an int 24h
  283. critical error message "FCB not availible". If this occurs while an application
  284. program is running, the value specified for 'm' in the FCBS command should be
  285. increased.
  286.  
  287.  When DOS determines the least recently used file to close, it does not include
  288. the first 'n' files opened, therefore the first 'n' files are protected from 
  289. being closed.
  290.  
  291.  
  292. RESTRICTIONS ON HANDLE USAGE├──────────────────────────────────────────────────
  293.  
  294.  The number of files that can be open simultaneously by all processes is 
  295. determined by the FILES command in the CONFIG.SYS file. The number of files a 
  296. single process can open depends on the value specified for the FILES command. If
  297. FILES is greater than or equal to 20, a single process can open 20 files. If 
  298. FILES is less than 20, the process can open less than 20 files. This value 
  299. includes three predefined handles: STDIN, STDOUT, and STDERR. This means only
  300. 17 additional handles can be added. DOS 3.3 includes a function to use more than
  301. 20 files per application.
  302.  
  303.  
  304. ALLOCATING SPACE TO A FILE├────────────────────────────────────────────────────
  305.  
  306.  Files are not nescessarily written sequentially on a disk. Space is allocated 
  307. as needed and the next location availible on the disk is allocated as space for
  308. the next file being written. Therefore, if considerable file generation has
  309. taken place, newly created files will not be written in sequential sectors.
  310. However, due to the mapping (chaining) of file space via the File Allocation
  311. Table (FAT) and the function calls availible, any file may be used in either a
  312. sequential or random manner.
  313.  
  314.  Space is allocated in increments called clusters. Cluster size varies 
  315. according to the media type. An application program should not concern itself 
  316. with the way that DOS allocates space to a file. The size of a cluster is only 
  317. important in that it determines the smallest amount of space that can be 
  318. allocated to a file. A disk is considered full when all clusters have been 
  319. allocated to files.
  320.  
  321.  
  322.  
  323. MSDOS / PCDOS DIFFERENCES├─────────────────────────────────────────────────────
  324.  
  325.  There is a problem of compatibility between MS-DOS and IBM PC-DOS having to 
  326. do with FCB Open and Create. The IBM 1.0, 1.1, and 2.0 documentation of OPEN
  327. (call 0Fh) contains the following statement:
  328.  
  329.  "The current block field (FCB bytes C-D) is set to zero [when an FCB is 
  330. opened]."
  331.  
  332.  This statement is NOT true of MS-DOS 1.25 or MS-DOS 2.00. The difference is
  333. intentional, and the reason is CP/M 1.4 compatibility. Zeroing that field is 
  334. not CP/M compatible. Some CP/M programs will not run when machine translated if
  335. that field is zeroed. The reason it is zeroed in the IBM versions is that IBM 
  336. specifically requested that it be zeroed. This is the reason for the complaints
  337. from some vendors about the fact that IBM MultiPlan will not run under MS-DOS.
  338. It is probably the reason that some other IBM programs don't run under MS-DOS.
  339.  
  340. NOTE: Do what all MS/PC-DOS systems programs do: Set every single FCB field you
  341. want to use regardless of what the documentation says is initialized.
  342.  
  343.  
  344. .COM FILE STRUCTURE├───────────────────────────────────────────────────────────
  345.  
  346.  The COM file structure was designed for DOS 1.0 and maximum compatibility 
  347. with programs ported from the CP/M operating system. COM files normally 
  348. comprise one segment only.
  349.  
  350.  
  351. .EXE FILE STRUCTURE├───────────────────────────────────────────────────────────
  352.  
  353.  The EXE file is the native mode for DOS. EXE files may make use of multiple 
  354. segments for code, stack, and data. The design of the EXE file reflects the 
  355. segmented design of the Intel 80x86 CPU architecture. EXE files may be as 
  356. large as availible memory and may make references to specific segment addresses.
  357.  
  358.  
  359.  The EXE files produced by the Linker program consist of two parts, control and
  360. relocation information and the load module itself.
  361.  
  362.  The control and relocation information, which is described below, is at the 
  363. beginning of the file in an area known as the header. The load module 
  364. immediately follows the header. The load module begins in the memory image of 
  365. the module contructed by the Linker.
  366.  
  367.  When you are loading a file with the name *.EXE, DOS does NOT assume that it
  368. is an EXE format file. It looks at the first two bytes for a signature telling
  369. it that it is an EXE file. If it has the proper signature, then the load 
  370. proceeds. Otherwise, it presumes the file to be a .COM format file.
  371.  
  372.  If the file has the EXE signature, then the internal consistency is checked.
  373. Pre-2.0 versions of MSDOS did not check the signature byte for EXE files.
  374.  
  375.  The .EXE format can support programs larger than 64K. It does this by 
  376. allowing separate segments to be defined for code, data, and the stack, each 
  377. of which can be up to 64K long. Programs in EXE format may contain explicit 
  378. references to segment addresses. A header in the EXE file has information for 
  379. DOS to resolve these references.
  380.  
  381.  
  382. The .EXE header is formatted as follows:
  383. ┌─────────┬───────────────────────────────────────────────────────────────────┐
  384. │ Offset  │                      C O N T E N T S                              │
  385. ├─────────┼─────┬─────────────────────────────────────────────────────────────┤
  386. │   00h   │ 4Dh │ This is the Linker's signature to mark the file as a valid  │ 
  387. ├─────────┼─────┤ .EXE file  (The ASCII letters M and Z, for Mark Zbikowski,  │
  388. │   01h   │ 5Ah │ one of the major designers of DOS at Microsoft)             │
  389. ├─────────┼─────┴─────────────────────────────────────────────────────────────┤
  390. │ 02h-03h │ Length of the image mod 512 (remainder after dividing the load    │
  391. │         │ module image size by 512)                                         │
  392. ├─────────┼───────────────────────────────────────────────────────────────────┤
  393. │ 04h-05h │ Size of the file in 512 byte pages including the header.          │ 
  394. ├─────────┼───────────────────────────────────────────────────────────────────┤
  395. │ 06h-07h │ Number of relocation table items following the header.            │
  396. ├─────────┼───────────────────────────────────────────────────────────────────┤
  397. │ 08h-09h │ Size of the header in 16 byte increments (paragraphs). This is    │
  398. │         │ used to locate the beginning of the load module in the file.      │
  399. ├─────────┼───────────────────────────────────────────────────────────────────┤
  400. │ 0Ah-0Bh │ Minimum number of 16 byte paragraphs required above the end of    │
  401. │         │ the loaded program.                                               │
  402. ├─────────┼───────────────────────────────────────────────────────────────────┤
  403. │ 0Ch-0Dh │ Maximum number of 16 byte paragraphs required above the end of    │
  404. │         │ the loaded program. If the minimum and maximum number of          │
  405. │         │ paragraphs are both zero, the program will be loaded as high in   │
  406. │         │ memory as possible.                                               │
  407. ├─────────┼───────────────────────────────────────────────────────────────────┤
  408. │ 0Eh-0Fh │ Displacement in paragraphs of stack segment within load module.   │
  409. │         │ This size must be adjusted by relocation.                         │
  410. ├─────────┼───────────────────────────────────────────────────────────────────┤
  411. │ 10h-11h │ Offset to be in SP register when the module is given control.     │
  412. ├─────────┼───────────────────────────────────────────────────────────────────┤
  413. │ 12h-13h │ Word Checksum - negative sum of all the words in the file,        │
  414. │         │ ignoring overflow.                                                │
  415. ├─────────┼───────────────────────────────────────────────────────────────────┤
  416. │ 14h-15h │ Offset to be in the IP register when the module is given control. │
  417. ├─────────┼───────────────────────────────────────────────────────────────────┤
  418. │ 16h-17h │ Displacement in paragraphs of code segment within load module.    │
  419. │         │ This size must be adjusted by relocation.                         │
  420. ├─────────┼───────────────────────────────────────────────────────────────────┤
  421. │ 18h-19h │ Displacement in bytes of the first relocation item in the file.   │
  422. ├─────────┼───────────────────────────────────────────────────────────────────┤
  423. │ 1Ah-1Bh │ Overlay number (0 for the resident part of the program)           │
  424. └─────────┴───────────────────────────────────────────────────────────────────┘
  425.  
  426.  
  427.  
  428. THE RELOCATION TABLE├──────────────────────────────────────────────────────────
  429.  
  430.  The word at 18h locates the first entry in the relocation table. The 
  431. relocation table is made up of a variable number of relocation items. The number
  432. of items is contained at offset 06-07. The relocation item contains two fields
  433. - a 2 byte offset value, followed by a 2 byte segment value. These two fields 
  434. represent the displacement into the load module before the module is given 
  435. control. The process is called relocation and is accomplished as follows:
  436.  
  437. 1. The formatted part of the header is read into memory. Its size is 1Bh.
  438.  
  439. 2. A portion of memory is allocated depending on the size of the load module
  440.    and the allocation numbers in offsets 0Ah-0Ch and 0Ch-0Dh. DOS always
  441.    tries to allocate 0FFFFh paragraphs. Since this call will always fail,
  442.    the function returns the amount of free memory. If this block is larger
  443.    than the minimum specified at offset 0Ah and the loaded program size,
  444.    DOS will allocate the size specified at offset 0Ch or the largest free
  445.    memory space, whichever is less.
  446.  
  447. 3. A Program Segment Prefix is built following the resident portion of the 
  448.    program that is performing the load operation.
  449.  
  450. 4. The formatted part of the header is read into memory (its size is at 
  451.    offset 08h)
  452.  
  453. 5. The load module size is determined by subtracting the header size from the 
  454.    file size. Offsets 04h and 08h can be used for this calculation. The 
  455.    actual size is downward adjusted based on the contents of offsets 02-03. 
  456.    Note that all files created by the Linker programs prior to version 1.10 
  457.    always placed a value of 4 at this location, regardless of the actual 
  458.    program size. Therefore, Microsoft recommends that this field be ignored if 
  459.    it contains a value of 4. Based on the setting of the high/low loader switch,
  460.    an appropriate segment is determined for loading the load module. This
  461.    segment is called the start segment.
  462.  
  463. 6. The load module is read into memory beginning at the start segment. The
  464.    relocation table is an ordered list of relocation items. The first relocation
  465.    item is the one that has the lowest offset in the file. 
  466.  
  467. 7. The relocation table items are read into a work area one or more at a time.
  468.  
  469. 8. Each relocation table item segment value is added to the start segment value.
  470.    The calculated segment, in conjunction with the relocation item offset value,
  471.    points to a word in the load module to which is added the start segment 
  472.    value. The result is placed back into the word in the load module.
  473.  
  474. 9. Once all the relocation items have been processed, the SS and SP registers 
  475.    are set from the values in the header and the start segment value is added 
  476.    to SS. The ES and DS registers are set to the segment address of the program 
  477.    segment prefix. The start segment value is added to the header CS register 
  478.    value. The result, along with the header IP value, is used to give the 
  479.    module control.
  480.  
  481.  
  482. "NEW" .EXE FORMAT (Microsoft Windows and OS/2)├────────────────────────────────
  483.  
  484.  The "old" EXE format is documented here. The "new" EXE format puts more 
  485. information into the header section and is currently used in applications that 
  486. run under Microsoft Windows. The linker that creates these files comes with the 
  487. Microsoft Windows Software Development Kit and is called LINK4. If you try to 
  488. run a Windows-linked program under DOS, you will get the error message "This 
  489. program requires Microsoft Windows".
  490.  
  491. PIF Files
  492.   PIF stands for "Program Information File". The PIF format was developed by 
  493. IBM for use with TopView, its multitasking manager. Microsoft also uses PIF 
  494. files to pass information regarding the amount of memory and type of I/O a 
  495. program running under Microsoft Windows requires.
  496.   The actual internal format of the PIF files is documented in the IBM TopView 
  497. Programmers' ToolKit.
  498.  
  499. STANDRD FILE CONTROL BLOCK├────────────────────────────────────────────────────
  500.  
  501.  The standard file control block is defined as follows, with offsets in hex:
  502.  
  503. ┌──────────────────────────────────────────────────────────────────────────────┐
  504. │                 F I L E      C O N T R O L      B L O C K                    │
  505. ├───────┬──────────────────────────────────────────────────────────────────────┤
  506. │ Bytes │                           Function                                   │
  507. ├───────┼──────────────────────────────────────────────────────────────────────┤
  508. │   0   │ 1 byte Drive number. For example:                                    │
  509. │       │ Before open:    00h = default drive                                  │
  510. │       │                 01h = drive A:                                       │
  511. │       │                 02h = drive B: etc.                                  │
  512. │       │ After open:     00h = drive C:                                       │
  513. │       │                 01h = drive A:                                       │
  514. │       │                 02h = drive B: etc.                                  │
  515. │       │ An 0 is replaced by the actual drive number during open.             │
  516. ├───────┼──────────────────────────────────────────────────────────────────────┤
  517. │  1-8  │ 8 bytes Filename, left justified with blanks. If a reserved device   │
  518. │       │ name is placed here (such as PRN) do not include the optional colon. │
  519. ├───────┼──────────────────────────────────────────────────────────────────────┤
  520. │  9-B  │ 3 bytes Filename extension, left justified with trailing blanks.     │
  521. ├───────┼──────────────────────────────────────────────────────────────────────┤
  522. │  C-D  │ 2 bytes Current block # relative to start of file, starting with 0   │
  523. │       │ (set to 0 by the open function call). A block consists of 128        │
  524. │       │ records, each of the size specified in the logical record size field.│
  525. │       │ The current block number is used with the current record field       │
  526. │       │ (below) for sequential reads and writes.                             │
  527. ├───────┼──────────────────────────────────────────────────────────────────────┤
  528. │  E-F  │ 2 bytes Logical record size in bytes. Set to 80h by OPEN function    │
  529. │       │ If this is not correct, you must set the value because DOS uses it   │
  530. │       │ to determine the proper locations in the file for all disk reads and │
  531. │       │ writes.                                                              │
  532. ├───────┼──────────────────────────────────────────────────────────────────────┤
  533. │ 10-13 │ 4 bytes File size in bytes. In this field, the first word is the     │
  534. │       │ low-order part of the size.                                          │
  535. ├───────┼──────────────────────────────────────────────────────────────────────┤
  536. │ 14-15 │ 2 bytes Date file was created or last updated. mm/dd/yy are mapped   │
  537. │       │ as follows:                                                          │
  538. │       │         15  14  13  12  11  10  9  8  7  6  5  4  3  2  1  0         │
  539. │       │         y   y   y   y   y   y   y  m  m  m  m  d  d  d  d  d         │
  540. │       │ where:            mm is 1-12                                         │
  541. │       │                   dd is 1-31                                         │
  542. │       │                   yy is 0-119 (1980-2099)                            │
  543. ├───────┼──────────────────────────────────────────────────────────────────────┤
  544. │ 16-17 │ 2 bytes time file was created or last updated.                       │
  545. ├───────┼──────────────────────────────────────────────────────────────────────┤
  546. │       │ These bytes contain the time when the file was created or last       │
  547. │       │  updated. The time is mapped in the bits as follows:                 │
  548. │       ├───────────────────────────────┬───────────────────────────────┐      │
  549. │       │         B Y T E   16h         │         B Y T E   17h         │      │
  550. │       ├───────────────────────────────┼───────────────────────────────┤      │
  551. │       │ F   E   D   C   B   A   9   8 │ 7   6   5   4   3   2   1   0 │      │
  552. │       ├───────────────────┬───────────┴───────────┬───────────────────┤      │
  553. │       │ H   H   H   H   H │ M   M   M   M   M   M │ D   D   D   D   D │      │
  554. │       ├───────────────────┼───────────────────────┼───────────────────┤      │
  555. │       │ binary # hrs 0-23 │ binary # minutes 0-59 │ bin. # 2-sec incr │      │
  556. │       ├───────────────────┴───────────────────────┴───────────────────┘      │
  557. │       │ note: The time is stored with the least significant byte first.      │
  558. ├───────┼──────────────────────────────────────────────────────────────────────┤
  559. │ 18-19 │ 2 bytes Reserved for DOS.                                            │
  560. ├───────┼──────────────────────────────────────────────────────────────────────┤
  561. │  20   │1 byte  Current relative record number (0-127) within the current     │
  562. │       │ block. This field and the Current Block field at offset 0Ch make up  │
  563. │       │ the record pointer. This field is not initialized by the OPEN        │
  564. │       │ function call. You must set this field before doing sequential read- │
  565. │       │ write operations to the diskette.                                    │
  566. ├───────┼──────────────────────────────────────────────────────────────────────┤
  567. │ 21-25 │ 4 bytes Relative Record. Points to the currently selected record,    │
  568. │       │ counting from the beginning of the file starting with 0. This field  │
  569. │       │ is not initialized by the OPEN system call. You must set this field  │
  570. │       │ before doing a random read or write to the file.                     │
  571. │       │  If the record size is less than 64 bytes, both words are used.      │
  572. │       │ Otherwise, only the first 3 bytes are used. Note that if you use the │
  573. │       │ File Control Block at 5Ch in the program segment, the last byte of   │
  574. │       │ the FCB overlaps the first byte of the unformatted parameter area.   │
  575. └───────┴──────────────────────────────────────────────────────────────────────┘
  576.  
  577. note 1) An unopened FCB consists of the FCB prefix (if used), drive number, and 
  578.         filename.ext properly filled in. An open FCB is one in which the 
  579.         remaining fields have been filled in by the CREAT or OPEN function 
  580.         calls.
  581.      2) Bytes 0-5 and 32-36 must be set by the user program. Bytes 16-31 are set
  582.         by DOS and must not be changed by user programs.
  583.      3) All word fields are stored with the least significant byte first. For 
  584.         example, a record length of 128 is stored as 80h at offset 14, and 00h 
  585.         at offset 15.
  586.  
  587.  
  588.  
  589. EXTENDED FILE CONTROL BLOCK├───────────────────────────────────────────────────
  590.  
  591.  The extended file control block is used to create or search for files in the 
  592. disk directory that have special attributes.
  593.  
  594. It adds a 7 byte prefix to the FCB, formatted as follows:
  595.  
  596. ┌──────────────────────────────────────────────────────────────────────────────┐
  597. │       E X T E N D E D     F I L E      C O N T R O L      B L O C K          │
  598. ├───────┬──────────────────────────────────────────────────────────────────────┤
  599. │ Bytes │                           Function                                   │
  600. ├───────┼──────────────────────────────────────────────────────────────────────┤
  601. │   0   │ Flag byte containing 0FFh to indicate an extended FCB.               │
  602. ├───────┼──────────────────────────────────────────────────────────────────────┤
  603. │  1-6  │ Reserved                                                             │
  604. ├───────┼──────────────────────────────────────────────────────────────────────┤
  605. │  6-7  │ Attribute byte. Refer to function call 11h (search first) for        │
  606. │       │ details on using the attribute bits during directory searches. This  │
  607. │       │ function is present to allow applications to define their own files  │
  608. │       │ as hidden (and thereby excluded from normal directory searches) and  │
  609. │       │ to allow selective directory searches.                               │
  610. └───────┴──────────────────────────────────────────────────────────────────────┘
  611.                                      
  612.  Any reference in the DOS function calls to an FCB, whether opened or unopened,
  613. may use either a normal or extended FCB. If you are using an extended FCB, the 
  614. appropriate register should be set to the first byte of the prefix, rather than
  615. the drive-number field.
  616.  
  617.  Common practice is to refer to the extended FCB as a negative offset from the 
  618. first byte of a standard File Control Block.
  619.  
  620.